<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/21
 * Time: 9:47
 *首页产品图相关大图，小图，颜色编辑上传
 */

require('../include/init.inc.php');
$method = $id = $model = $search = $products_id = $products_model = $uploadfile = '';
extract($_REQUEST, EXTR_IF_EXISTS);


if (Common::isPost()) {
    $img_src = '';
    if ($uploadfile) {
        $img_src = $uploadfile;
    }

    $prod = AdminProducts::getProductById($products_id);
    if (!$prod) {
        Common::exitWithError(ErrorMessage::PRODUCT_NOT_EXIST, "one_page_shop/product_add_small.php");
    }

    $up_data = array('products_small_images' => $img_src);
    $where = "WHERE products_id=" . $products_id;
    $ret = AdminProducts::update($where, $up_data);
    if ($ret) {
        SysLog::addLog(UserSession::getUserName(), 'Update', 'SmallImagesAdd', $products_model, json_encode($up_data));
        Common::exitWithSuccess('添加完成', 'one_page_shop/home_product.php');
    } else {
        OSAdmin::alert("error");
    }
}

$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign('osadmin_action_confirm', $confirm_html);
Template::assign('pid', $id);
Template::assign('model', $model);
Template::display('one_page_shop/add_small.tpl');